package com.my.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.StockRemovalService;
import com.my.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 出库表 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2018-08-25
 */
@Controller
@RequestMapping("/stockRemoval")
public class StockRemovalController {

    @Autowired
    StockRemovalService stockRemovalService;

    //查询列表表格
    @RequestMapping("/list")
    @ResponseBody
    public ResultPage<StockRemoval> list(VoPage voPage, StockRemoval stockRemoval, HttpSession session) {
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid = ((User)session.getAttribute("user")).getAreaId();
        return  stockRemovalService.selectMyPage(voPage,stockRemoval,areaid,admin);
    }


    //添加
    @RequestMapping("/insertStockRemoval")
    @ResponseBody
    public String insert(String param,HttpSession session) {

        try {
            boolean admin=false;
            //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
            if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
                admin=true;
            }
			//使用反射吧json字符串转换成实体类对象
			Stock stock = JSONObject.parseObject(param,Stock.class);
			//按照创建日期倒叙排序

            Long areaid = ((User)session.getAttribute("user")).getAreaId();
            return  stockRemovalService.insertStockRemoval(param,areaid,admin);
        } catch (SQLException e) {
            return "出库失败，服务器错误";
        }
    }
    //跳转
    @RequestMapping("/main.html")
    public String main() {
        return "Meal/StockRenmovall";
    }
    //跳转
    @RequestMapping("/stockRemoval_add.html")
    public String stockRemoval_add() {
        return "/Alert/stockRemoval_add";
    }

}







